define(['common/js/service/classtype-service.js',
        'common/js/service/boss-storage-service-0.1'],
    function () {
        controllerModule.controller("ClassTypeController", function ($scope, ClassTypeService, cookieDataStorage, dataStorage, MaiDialog) {
        	$scope.columnDefs=[{
    			field: 'classTypeId',
    			width: '10%',
    			displayName: '类别ID'
    		},{
    			field: 'classTypeName',
    			width: '20%',
    			displayName: '类别名称'
    		},{
    			field: 'superClassName',
    			width: '20%',
    			displayName: '一级归属'
    		},{
    			field: 'classTypeIcon',
    			width: '10%',
    			displayName: '图标代号'
    		},{
    			field: 'businessNum',
    			width: '10%',
    			displayName: '商家数量'
    		},{
    			field: 'operate',
    			width: '30%',
    			displayName: '操作',
                cellTemplate: function(entity){
    				var menu = "<a class='btn btn-primary' ng-click='deleteById(entity)'>删除</a>";
    				return menu;
    			}
    		}];
        	
        	/**
        	 * 打开新增窗口
        	 */
        	$scope.openAdd = function(){
        		$("#addDialog").modal("show");
        	}
        	
        	window.refresh = function(){
        		$scope.$broadcast('reloadGrid');
        	}
        	
        	/**
        	 */
        	$scope.deleteById = function(entity){
        		var classType = {"classTypeId":entity.classTypeId};
        		ClassTypeService.deleteById(classType).then(function(data){
        			if(data.code == 200){
        				$scope.$broadcast('reloadGrid');
        			}else{
        				MaiDialog.alert(data.msg);
        			}
        		});
        	}
        });
        
        
        controllerModule.controller("ClassTypeAddController", function ($scope, ClassTypeService, cookieDataStorage, dataStorage, MaiDialog) {
        	$scope.save = function(param){
        		var classType = {"classTypeName":param.classTypeName,"classTypeIcon":param.classTypeIcon,"superClassId":param.superClassId};
        		ClassTypeService.save(classType).then(function(data){
        			if(data.code == 200){
        				$("#addDialog").modal("hide");
        				window.refresh();
        			}else{
        				MaiDialog.alert("保存失败");
        			}
        		});
        	}
        });
    });